/*
 * @Author: zhang xinzheng
 * @Date: 2022-01-20 14:30:56
 * @LastEditors: zhang xinzheng
 * @LastEditTime: 2022-01-20 17:21:08
 * @Description: 
 * @FilePath: \report-service\src\Charts\AxisChart.ts
 */
import DataSource, { DataSourceMgr } from "../dataSource/dataSource"
import Charts, { IChartConfig, ChartConfigMgr } from "./Charts"
import { EChartType, EAxisChartDimension } from "../core/ChartType"
export enum EAxisType {
    Category = 'category',
    Value = "value",
    Time = 'time',
    Log = 'log'
}
export interface IAriesChartOptions {
    title: string;
    text: string;
    description: string;
}
export interface IAriesChartConfig extends IChartConfig {
    ChartOptions: IAriesChartOptions
}
export default class AxisChart extends Charts<IAriesChartConfig>{
    constructor(config: { [key: string]: any }, dataSource: DataSourceMgr, id?: string) {
        super(config, dataSource, id)
    }
    computedConifgStrategy(data: any) {
        let options = <Map<keyof IAriesChartConfig, any>>this.getConfig();
        const dataLength = options.get("limit") || 0;
        if (dataLength) {
            data = data.slice(0, dataLength);
        }
        let axisConfig = options.get("chartOptions");
        if (!axisConfig.text)
            return;
        try {
            if (typeof axisConfig.text == "string") {
                const textConfFn = new Function("$originData", axisConfig.text);
                axisConfig.text = textConfFn(data);
            }
            this.setConfig("chartOptions", axisConfig)
        } catch (error) {
            console.error(error)
        }
    }
}